/* 
 * @(#)MimeServlet.java    Created on 5:52:19 PM Dec 27, 2011
 * 
 * Copyright © Longshine Corporation. All rights reserved.
 */
package com.lc.cn.managersys.common;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>Title: 电动汽车智能充换电服务网络运营管理系统_核算_[模块名]</p>
 * <p>Description： [描述该类概要功能]</p>
 *
 * @author Administrator
 * @version $Revision$
 * @author (latest modification by $Author$)
 * @version since 1.0
 */
public class MimeServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public MimeServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("application/pdf");
		response.setHeader("Content-Disposition", "inline; filename=\"" + "a.pdf" + "\"");
		File f = new File("E:\\workspace\\manager-sys\\managersys\\WebRoot\\word\\b.pdf");
		BufferedInputStream bis = new BufferedInputStream(
				new FileInputStream(f));
		BufferedOutputStream bos = new BufferedOutputStream(response
				.getOutputStream());
		byte buff[] = new byte[4096];
		int bytesRead;
		while (-1 != (bytesRead = bis.read(buff, 0, buff.length)))
			bos.write(buff, 0, bytesRead);
		if (bis != null)
			bis.close();
		if (bos != null) {
			bos.flush();
			bos.close();
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
